package com.wmb.loggingservice.service;

import com.alibaba.fastjson.JSON;
import com.wmb.loggingservice.mapper.LoggingMapper;
import com.wmb.loggingservice.model.pojo.OperationLog;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@RocketMQMessageListener(topic = "TestTopic", consumerGroup = "cloud-demo-group")
public class LoggingService implements RocketMQListener<String> {

    @Autowired
    private LoggingMapper loggingMapper;

    @Override
    public void onMessage(String message) {
        OperationLog operationLog = JSON.parseObject(message, OperationLog.class);
        loggingMapper.insert(operationLog);
        System.out.printf("------- StringConsumer received: %s \n", operationLog);

    }
}